﻿#include "MineInfo.h"
#include "../../Shared/Functions/Functions.h"

namespace Server::MirDatabase
{

    MineSet::MineSet(unsigned char mineType)
    {
        switch (mineType)
        {
            case 1:
                TotalSlots = 120;
                MineDrop *tempVar = new MineDrop();
                tempVar->ItemName = "GoldOre";
                tempVar->MinSlot = 1;
                tempVar->MaxSlot = 2;
                tempVar->MinDura = 3;
                tempVar->MaxDura = 16;
                tempVar->BonusChance = 20;
                tempVar->MaxBonusDura = 10;
                Drops.push_back(tempVar);
                MineDrop *tempVar2 = new MineDrop();
                tempVar2->ItemName = "SilverOre";
                tempVar2->MinSlot = 3;
                tempVar2->MaxSlot = 20;
                tempVar2->MinDura = 3;
                tempVar2->MaxDura = 16;
                tempVar2->BonusChance = 20;
                tempVar2->MaxBonusDura = 10;
                Drops.push_back(tempVar2);
                MineDrop *tempVar3 = new MineDrop();
                tempVar3->ItemName = "CopperOre";
                tempVar3->MinSlot = 21;
                tempVar3->MaxSlot = 45;
                tempVar3->MinDura = 3;
                tempVar3->MaxDura = 16;
                tempVar3->BonusChance = 20;
                tempVar3->MaxBonusDura = 10;
                Drops.push_back(tempVar3);
                MineDrop *tempVar4 = new MineDrop();
                tempVar4->ItemName = "BlackIronOre";
                tempVar4->MinSlot = 46;
                tempVar4->MaxSlot = 56;
                tempVar4->MinDura = 3;
                tempVar4->MaxDura = 16;
                tempVar4->BonusChance = 20;
                tempVar4->MaxBonusDura = 10;
                Drops.push_back(tempVar4);
                break;
            case 2:
                TotalSlots = 100;
                MineDrop *tempVar5 = new MineDrop();
                tempVar5->ItemName = "PlatinumOre";
                tempVar5->MinSlot = 1;
                tempVar5->MaxSlot = 2;
                tempVar5->MinDura = 3;
                tempVar5->MaxDura = 16;
                tempVar5->BonusChance = 20;
                tempVar5->MaxBonusDura = 10;
                Drops.push_back(tempVar5);
                MineDrop *tempVar6 = new MineDrop();
                tempVar6->ItemName = "RubyOre";
                tempVar6->MinSlot = 3;
                tempVar6->MaxSlot = 20;
                tempVar6->MinDura = 3;
                tempVar6->MaxDura = 16;
                tempVar6->BonusChance = 20;
                tempVar6->MaxBonusDura = 10;
                Drops.push_back(tempVar6);
                MineDrop *tempVar7 = new MineDrop();
                tempVar7->ItemName = "NephriteOre";
                tempVar7->MinSlot = 21;
                tempVar7->MaxSlot = 45;
                tempVar7->MinDura = 3;
                tempVar7->MaxDura = 16;
                tempVar7->BonusChance = 20;
                tempVar7->MaxBonusDura = 10;
                Drops.push_back(tempVar7);
                MineDrop *tempVar8 = new MineDrop();
                tempVar8->ItemName = "AmethystOre";
                tempVar8->MinSlot = 46;
                tempVar8->MaxSlot = 56;
                tempVar8->MinDura = 3;
                tempVar8->MaxDura = 16;
                tempVar8->BonusChance = 20;
                tempVar8->MaxBonusDura = 10;
                Drops.push_back(tempVar8);
                break;

//C# TO C++ CONVERTER TODO TASK: A 'delete tempVar8' statement was not added since tempVar8 was passed to a method or constructor. Handle memory management manually.
//C# TO C++ CONVERTER TODO TASK: A 'delete tempVar7' statement was not added since tempVar7 was passed to a method or constructor. Handle memory management manually.
//C# TO C++ CONVERTER TODO TASK: A 'delete tempVar6' statement was not added since tempVar6 was passed to a method or constructor. Handle memory management manually.
//C# TO C++ CONVERTER TODO TASK: A 'delete tempVar5' statement was not added since tempVar5 was passed to a method or constructor. Handle memory management manually.
//C# TO C++ CONVERTER TODO TASK: A 'delete tempVar4' statement was not added since tempVar4 was passed to a method or constructor. Handle memory management manually.
//C# TO C++ CONVERTER TODO TASK: A 'delete tempVar3' statement was not added since tempVar3 was passed to a method or constructor. Handle memory management manually.
//C# TO C++ CONVERTER TODO TASK: A 'delete tempVar2' statement was not added since tempVar2 was passed to a method or constructor. Handle memory management manually.
//C# TO C++ CONVERTER TODO TASK: A 'delete tempVar' statement was not added since tempVar was passed to a method or constructor. Handle memory management manually.
        }
    }

    void MineSet::SetDrops(std::vector<ItemInfo*> &items)
    {
        if (DropsSet)
        {
            return;
        }
        for (int i = 0; i < Drops.size(); i++)
        {
            for (int j = 0; j < items.size(); j++)
            {
                ItemInfo *info = items[j];
//C# TO C++ CONVERTER TODO TASK: The following System.String compare method is not converted:
                if (std::string::Compare(StringHelper::replace(info->Name, " ", ""), Drops[i]->ItemName, StringComparison::OrdinalIgnoreCase) != 0)
                {
                    continue;
                }
                Drops[i]->Item = info;
                break;
            }
        }
        DropsSet = true;
    }

    MineZone::MineZone()
    {
    }

    MineZone::MineZone(BinaryReader *reader)
    {
        Location = new Point(reader->ReadInt32(), reader->ReadInt32());
        Size = reader->ReadUInt16();
        Mine = reader->ReadByte();
    }

    void MineZone::Save(BinaryWriter *writer)
    {
        writer->Write(Location->X);
        writer->Write(Location->Y);
        writer->Write(Size);
        writer->Write(Mine);
    }

    std::string MineZone::ToString()
    {
        return StringHelper::formatSimple("Mine: {0}- {1}", Functions::PointToString(Location), Mine);
    }
}
